const pagination = require('mongoose-sex-page');
const { Comment } = require('../../model/comment');
module.exports = async (req,res)=>{
  //已批准
  if (req.body.state == 1){
    let page = req.query.page;
    let comments = await pagination(Comment).find({state: 1}).populate('uid').populate('aid').page(page).size(5).display(3).exec();
    comments = JSON.stringify(comments);
    comments = JSON.parse(comments);
    res.render('admin/commentList',{
      comments
    })
  }
  //未批准
  else if (req.body.state == 0){
    let page = req.query.page;
    let comments = await pagination(Comment).find({state: 0}).populate('uid').populate('aid').page(page).size(5).display(3).exec();
    comments = JSON.stringify(comments);
    comments = JSON.parse(comments);
    res.render('admin/commentList',{
      comments
    })
  }
  //所有
  else{
    let page = req.query.page;
    let comments = await pagination(Comment).find().populate('uid').populate('aid').page(page).size(5).display(3).exec();
    comments = JSON.stringify(comments);
    comments = JSON.parse(comments);
    res.render('admin/commentList',{
      comments
    })
  }
}